#include "npc4bomb.h"
#include "../common.h"

namespace fireplane{

	Npc4Bomb::Npc4Bomb( EffectType type ):
		Effect(type),_bomb(NULL)
	{}

	Npc4Bomb::~Npc4Bomb()
	{

	}

	void Npc4Bomb::init(CreateCmd* cmd)
	{
		CreateNpc4Bomb0* tcmd = (CreateNpc4Bomb0*)cmd;
		_bomb = NULL;

		_bomb = CCSprite::create("effect/npc4bomb/0.png");
		addChild(_bomb);

		CCPoint pos = tcmd->worldPos;
		pos = Effect::getAllEffectParent()->convertToNodeSpace(pos);
		this->setPosition(pos);

		CCActionInterval* action = Common::createFrameAnimation("effect/npc4bomb/",11,CCRectMake(0,0,116,94));
		_bomb->runAction(action);
		_bomb->runAction(CCFadeOut::create(0.5f));
		_bomb->runAction(CCScaleTo::create(0.5f,2.0f));

		scheduleUpdate();
	}

	void Npc4Bomb::destroyThis()
	{
		this->removeFromParentAndCleanup(true);
	}

	void Npc4Bomb::update( float delta )
	{
		if(_bomb->numberOfRunningActions() == 0){
			destroyThis();
		}
	}
	//////////////////////////////////////////////////////////////////////////
	Npc4Bomb1::Npc4Bomb1( EffectType type ):
	Effect(type),_bomb0(NULL),_bomb1(NULL)
	{}

	Npc4Bomb1::~Npc4Bomb1()
	{

	}

	void Npc4Bomb1::init(CreateCmd* cmd)
	{
		CreateNpc4Bomb0* tcmd = (CreateNpc4Bomb0*)cmd;
		_bomb0 = NULL;
		_bomb1 = NULL;

		_bomb0 = CCSprite::create("effect/npc4bomb1/0.png");
		addChild(_bomb0);

		CCPoint pos = tcmd->worldPos;
		pos = Effect::getAllEffectParent()->convertToNodeSpace(pos);
		this->setPosition(pos);

		CCActionInterval* action = Common::createFrameAnimation("effect/npc4bomb1/",10,CCRectMake(0,0,182,150));
		_bomb0->runAction(action);
		_bomb0->runAction(CCFadeOut::create(0.8f));
		_bomb0->runAction(CCScaleTo::create(0.5f,3.0f));


		_bomb1 = CCSprite::create("effect/npc4bomb1/circle.png");
		addChild(_bomb1);
		_bomb1->setScale(0.1f);
		_bomb1->runAction(CCScaleTo::create(0.5f,1.0f));
		_bomb1->runAction(CCFadeOut::create(0.5f));

		scheduleUpdate();
	}

	void Npc4Bomb1::destroyThis()
	{
		this->removeFromParentAndCleanup(true);
	}

	void Npc4Bomb1::update( float delta )
	{
		if(_bomb0->numberOfRunningActions() == 0 && _bomb1->numberOfRunningActions() == 0){
			destroyThis();
		}
	}
}